<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta content="width=device-width, initial-scale=1.0" name="viewport">
    <title>教师测评 - IVT绩效考核系统</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
            background-color: #f5f5f5;
            color: #333;
        }

        .header {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            padding: 15px 20px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
            display: flex;
            align-items: center;
        }

        .back-btn {
            background: none;
            border: none;
            color: white;
            font-size: 18px;
            cursor: pointer;
            margin-right: 15px;
            padding: 5px;
        }

        .header h1 {
            font-size: 20px;
            font-weight: 600;
        }

        .container {
            margin: 20px;
        }

        .list-item {
            background: white;
            margin-bottom: 15px;
            padding: 20px;
            border-radius: 10px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
            cursor: pointer;
            transition: transform 0.2s, box-shadow 0.2s;
        }

        .list-item:hover {
            transform: translateY(-2px);
            box-shadow: 0 4px 20px rgba(0,0,0,0.15);
        }

        .teacher-name {
            font-size: 18px;
            font-weight: 600;
            margin-bottom: 8px;
            color: #7b1fa2;
        }

        .teacher-info {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 10px;
        }

        .dept-info {
            font-size: 14px;
            color: #666;
        }

        .indicator-info {
            font-size: 14px;
            color: #666;
        }

        .score-info {
            font-size: 14px;
            color: #ff9800;
            font-weight: 600;
        }

        .status {
            padding: 4px 8px;
            border-radius: 12px;
            font-size: 12px;
            font-weight: 600;
        }

        .status.pending {
            background: #fff3e0;
            color: #f57c00;
        }

        .loading {
            text-align: center;
            padding: 50px;
            color: #666;
        }

        .empty {
            text-align: center;
            padding: 50px;
            color: #999;
        }

        .error {
            background: #ffebee;
            color: #c62828;
            padding: 15px;
            margin: 20px;
            border-radius: 8px;
            text-align: center;
        }


    </style>
</head>
<body>
<div class="header">
    <button class="back-btn" onclick="goBack()">‹</button>
    <h1>教师测评</h1>
</div>

<div class="loading" id="loading">
    正在加载教师列表...
</div>

<div class="error" id="error" style="display:none;"></div>

<div class="container" id="container" style="display:none;">
    <!-- 动态加载教师列表 -->
</div>

<script>
        let currentUser = null;

        // 获取当前用户信息
        function getCurrentUser() {
            const userData = localStorage.getItem('currentUser');
            return userData ? JSON.parse(userData) : null;
        }

        // 返回上一页
        function goBack() {
            history.back();
        }

        // 跳转到测评页面
        function goToEvaluation(relationId, teacherName, deptName, totalScore) {
            const url = `teacher-evaluation.html?relationId=${relationId}&teacherName=${encodeURIComponent(teacherName)}&deptName=${encodeURIComponent(deptName)}&totalScore=${totalScore}`;
            location.href = url;
        }

        // 加载教师测评列表
        async function loadTeacherList() {
            currentUser = getCurrentUser();
            if (!currentUser) {
                showError('请先登录');
                return;
            }

            try {
                const response = await fetch('/evaluation/api/h5/teacher/pending');
                const result = await response.json();

                if (result.success) {
                    renderTeacherList(result.data);
                } else {
                    // 检查是否是登录超时
                    if (result.message && (result.message.includes('登录') || result.message.includes('未登录'))) {
                        handleLoginTimeout();
                        return;
                    }
                    showError(result.message || '加载失败');
                }
            } catch (error) {
                console.error('加载教师列表失败:', error);
                showError('网络错误，请稍后重试');
            }
        }

        // 渲染教师列表
        function renderTeacherList(teacherList) {
            const container = document.getElementById('container');
            const loading = document.getElementById('loading');

            loading.style.display = 'none';
            container.style.display = 'block';

            if (!teacherList || teacherList.length === 0) {
                container.innerHTML = '<div class="empty">暂无待测评教师</div>';
                return;
            }

            const html = teacherList.map(item => `
                <div class="list-item" onclick="goToEvaluation(${item.bh}, '${item.bcpjs || '未知教师'}', '${item.bcpjsbm || '未知部门'}', ${item.totalscore || 100})">
                    <div class="teacher-name">${item.bcpjs || '未知教师'}</div>
                    <div class="teacher-info">
                        <div class="dept-info">${item.bcpjsbm || '未知部门'}</div>
                        <div class="score-info">总分：${item.totalscore || 100}分</div>
                    </div>
                    <div class="status pending">待测评</div>
                </div>
            `).join('');

            container.innerHTML = html;
        }

        function showError(message) {
            document.getElementById('loading').style.display = 'none';
            document.getElementById('error').style.display = 'block';
            document.getElementById('error').textContent = message;
        }

        // 处理登录超时
        function handleLoginTimeout() {
            // 清除本地存储的用户信息
            localStorage.removeItem('currentUser');
            
            // 显示提示信息
            alert('登录已过期，请重新登录');
            
            // 跳转到登录页面
            window.location.href = 'index.html';
        }

        // 页面加载时获取教师列表
        window.onload = function() {
            loadTeacherList();
        };


</script>
</body>
</html>
